package cn.change.org.controller;
import cn.change.basic.util.AjaxResult;
import cn.change.basic.util.PageList;
import cn.change.org.domain.ShopAuditLog;
import cn.change.org.query.ShopAuditLogQuery;
import cn.change.org.service.ShopAuditLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/shopAuditLog")
public class ShopAuditLogController {
    @Autowired
    private ShopAuditLogService shopAuditLogService;
    /**
     * 保存和修改公用的
     * @param shopAuditLog  传递的实体
     * @return Ajaxresult转换结果
     */
    @PutMapping
    public AjaxResult addOrUpdate(@RequestBody ShopAuditLog shopAuditLog){
        try {
            if( shopAuditLog.getId()!=null)
                shopAuditLogService.update(shopAuditLog);
            else
                shopAuditLogService.add(shopAuditLog);
            return AjaxResult.me();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMessage("保存对象失败！"+e.getMessage());
        }
    }
    /**
     * 删除对象信息
     * @param id
     * @return
     */
    @DeleteMapping(value="/{id}")
    public AjaxResult delete(@PathVariable("id") Long id){
        try {
            shopAuditLogService.remove(id);
            return AjaxResult.me();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMessage("删除对象失败！"+e.getMessage());
        }
    }

    //获取用户
    @GetMapping("/{id}")
    public ShopAuditLog loadById(@PathVariable("id")Long id)
    {
        return shopAuditLogService.queryById(id);
    }


    /**
     * 查看所有的员工信息
     * @return
     */
    @GetMapping()
    public List<ShopAuditLog> list(){

        return shopAuditLogService.queryAll();
    }

    /**
     * 分页查询数据
     *
     * @param query 查询对象
     * @return PageList 分页对象
     */
    @PostMapping("/list")
    public PageList<ShopAuditLog> loadPage(@RequestBody ShopAuditLogQuery query)
    {
        return shopAuditLogService.queryPage(query);
    }
}

